package com.senlingspace.web.controller.headquarters;

import java.util.List;

import com.github.pagehelper.PageInfo;
import com.senlingspace.system.domain.SlkjShiftManagement;
import com.senlingspace.system.domain.SlkjShopProject;
import com.senlingspace.system.domain.dto.ShopUpdateStatusDto;
import com.senlingspace.system.domain.dto.SlkjShopDto;
import com.senlingspace.system.service.ISlkjShiftManagementService;
import com.senlingspace.system.service.ISlkjShopProductService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.senlingspace.common.annotation.Log;
import com.senlingspace.common.core.controller.BaseController;
import com.senlingspace.common.core.domain.AjaxResult;
import com.senlingspace.common.enums.BusinessType;
import com.senlingspace.system.domain.SlkjShop;
import com.senlingspace.system.service.ISlkjShopService;
import com.senlingspace.common.core.page.TableDataInfo;

/**
 * 门店Controller
 *
 * @author SenlingSpace
 * @date 2024-06-27
 */
@RestController
@RequestMapping("/system/shop")
public class SlkjShopController extends BaseController {
    @Autowired
    private ISlkjShopService slkjShopService;
    @Autowired
    private ISlkjShiftManagementService slkjShiftManagementService;
    @Autowired
    private ISlkjShopProductService iSlkjShopProductService;


    /**
     * 查询门店列表
     */
    @PreAuthorize("@ss.hasPermi('system:shop:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlkjShopDto slkjShopDto) {
        List<SlkjShopDto> list = slkjShopService.selectSlkjShopList(slkjShopDto);
        return getDataTable(list);
    }


    //
    // /**
    //  * 导出门店列表
    //  */
    // @PreAuthorize("@ss.hasPermi('system:shop:export')")
    // @Log(title = "门店", businessType = BusinessType.EXPORT)
    // @PostMapping("/export")
    // public void export(HttpServletResponse response, SlkjShop slkjShop)
    // {
    //     List<SlkjShop> list = slkjShopService.selectSlkjShopList(slkjShop);
    //     ExcelUtil<SlkjShop> util = new ExcelUtil<SlkjShop>(SlkjShop.class);
    //     util.exportExcel(response, list, "门店数据");
    // }

    /**
     * 获取门店详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:shop:query')")
    @GetMapping(value = "/{shopId}")
    public AjaxResult getInfo(@PathVariable("shopId") Long shopId) {
        return success(slkjShopService.selectSlkjShopByShopId(shopId));
    }

    /**
     * 新增门店
     */
    @PreAuthorize("@ss.hasPermi('system:shop:add')")
    @Log(title = "门店", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlkjShop slkjShop) {
        return toAjax(slkjShopService.insertSlkjShop(slkjShop));
    }

    /**
     * 修改门店
     */
    @PreAuthorize("@ss.hasPermi('system:shop:edit')")
    @Log(title = "门店", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlkjShop slkjShop) {
        return toAjax(slkjShopService.updateSlkjShop(slkjShop));
    }


    /**
     * 门店状态修改
     *
     * @param statusDto
     * @return com.senlingspace.common.core.domain.AjaxResult
     * @author wangliang
     */
    @PreAuthorize("@ss.hasPermi('system:shop:open')")
    @Log(title = "修改门店状态", businessType = BusinessType.UPDATE)
    @PutMapping("/updateStatus")
    public AjaxResult updateStatus(@RequestBody ShopUpdateStatusDto statusDto) {
        return toAjax(slkjShopService.updateStatus(statusDto.getStatus(), statusDto.getId()));
    }


    /**
     * 删除门店
     */
    @PreAuthorize("@ss.hasPermi('system:shop:remove')")
    @Log(title = "门店", businessType = BusinessType.DELETE)
    @DeleteMapping("/{shopId}")
    public AjaxResult remove(@PathVariable Long shopId) {
        return toAjax(slkjShopService.deleteSlkjShopByShopId(shopId));
    }

    /**
     * 添加项目
     *
     * @param shopProjects
     * @return
     */
    @PostMapping("/addProject")
    public AjaxResult addProject(@RequestBody List<SlkjShopProject> shopProjects) {
        if (CollectionUtils.isEmpty(shopProjects)) {
            return AjaxResult.error("入参不能为空！");
        }
        slkjShopService.addProject(shopProjects);
        return AjaxResult.success();
    }

    /**
     * 编辑项目
     *
     * @param shopProjects
     * @return
     */
    @PutMapping("/editProject")
    public AjaxResult editProject(@RequestBody List<SlkjShopProject> shopProjects) {
        if (CollectionUtils.isEmpty(shopProjects)) {
            return AjaxResult.error("入参不能为空！");
        }
        slkjShopService.editProject(shopProjects);
        return AjaxResult.success();
    }

    /**
     * 门店是否存在票价方案
     *
     * @param id 门店 ID
     * @return {@link AjaxResult }
     */
    @GetMapping("/existsFareScheme")
    public AjaxResult existsFareScheme(@RequestParam Long id) {
        return slkjShopService.existsFareScheme(id);
    }

    /**
     * 门票上架信息检查
     *
     * @param shopId 门店 ID
     * @return {@link AjaxResult }
     */
    @GetMapping("/storeCheck")
    @PreAuthorize("@ss.hasPermi('system:shop:check')")
    public AjaxResult storeListingInformationCheck(@RequestParam Long shopId) {
        return slkjShopService.storeListingInformationCheck(shopId);
    }

    @GetMapping("settlement")
    public TableDataInfo settlement(SlkjShiftManagement slkjShiftManagement, Long deptId) {
        PageInfo<SlkjShiftManagement> pageInfo = slkjShiftManagementService.selectSlkjShiftManagementList(slkjShiftManagement, deptId);
        return getDataTable(pageInfo);
    }
}
